package com.xiao.permission_system.service.impl;

import com.xiao.permission_system.entity.Role;
import com.xiao.permission_system.mapper.RoleMapper;
import com.xiao.permission_system.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author beth
 * @since 2019-10-26
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

         @Autowired
         private RoleMapper  iRoleMapper;

        /**
         * <p>
         * 插入一条记录
         * </p>
         *
         * @param entity 实体对象
         * @return 插入成功记录数
         */
        public int insert(Role entity) {
           Integer result = iRoleMapper.insert(entity);
           return result;
        }

        /**
         * <p>
         * 根据 ID 删除
         * </p>
         *
         * @param id 主键ID
         * @return 删除成功记录数
         */
          public int deleteById(String id) {
              Integer result = iRoleMapper.deleteById(id);
              return result;
          }

          /**
           * <p>
           * 根据 ID 查询
           * </p>
           *
           * @param id 主键ID
           * @return 实体
           */
           public  Role  selectById(String id){
              Role  result = iRoleMapper.selectById(id);
              return result;
           }

           /**
            * <p>
            * 根据 ID 修改
            * </p>
            *
            * @param entity 实体对象
            * @return 修改成功记录数
            */
            public boolean updateById(Role entity) {
              int result = iRoleMapper.updateById(entity);
              if(result>0){
                 return  true;
               }
               return false;
            }

             /**
              * 分页查询
              * @param page 分页信息
              * @param wrapper 查询条件
              * @return
              */
              public  IPage<Role> selectPage(Page<Role> page, @Param(Constants.WRAPPER) Wrapper<Role> wrapper) {
                 return iRoleMapper.selectPage(page,wrapper);
              }

}
